package com.qf.web.servlet;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.qf.service.OrderService;
import com.qf.service.impl.OrderServiceImpl;
import com.qf.utils.StringConstans;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Create by 周志豪 on 2022/8/19 19:52
 *
 * @authoe 周志豪
 * @veision 1.0
 * //TODO  想好了再去做
 * @since 1.0
 */

public class ResultServlet {
    private ObjectMapper objectMapper = new ObjectMapper();

    private OrderService orderService = new OrderServiceImpl();

    public String defaultMethod(HttpServletRequest request, HttpServletResponse response) {
        String resultJson = request.getParameter("result");
        try {
            Map map = objectMapper.readValue(resultJson, Map.class);
            Map payResult = (Map) map.get("result");
            String oid = (String) payResult.get("out_trade_no");
            orderService.updateOrderStaus(oid, "1");
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
        return StringConstans.REDIRECT + "/order?method=show";

    }
}
